package gamePieces;



import gameComponents.Board;
import gameComponents.Player;

import java.awt.Point;
import java.util.ArrayList;

/**
 * Class for the chess piece of a Rook
 * @author Jordan
 *
 */
public class Rook extends Piece{
	/**
	 * Default constructor for Rook object.
	 * X and Y coordinates of Rook are set in the superclass Piece. 
	 * 
	 * @param x coordinate of Rook
	 * @param y coordinate of Rook
	 */
	public Rook(int x, int y, Player player) {
		super(x,y, player);
	}
	
	/**
	 * toString method
	 * @return The string representation of a Rook on the board.
	 * @author Vivian Andreeva
	 * @modified by Selman Selman
	 */
	public String toString() {
		if (getOwnership().getId()==1) {
		return "R";
		}
		return "r";
	}

	 /**
	  * Overrides abstract method in superclass Piece.
	  * Calculates list of all possible moves of
	  * the Rook object at its current position.
	  * Rook piece can move any number of squares in a line horizontally and vertically.
	  * @author Sabrina Gaudreau
	  * @return an ArrayList of all the points the knight could IDEALLY move to.
	  */
	@Override 
	public ArrayList<Point> possibleMoves(){
		
		int x = super.getX();
		int y = super.getY();
		moves = new ArrayList<Point>(); //will contain coordinates of all possible moves
		//all possible moves in the horizontal right
		for(int i = x + 1; i < Board.SIZE; i++){
			moves.add(new Point(i, y));
		}
		//all possible moves in the horizontal left
		for(int i = x -1; i >= 0; i--){
			moves.add(new Point(i,y));
		}
		//all possible moves in the vertical down
		for(int j = y + 1; j < Board.SIZE; j++){
			moves.add(new Point(x,j));
		}
		//all possible moves in the vertical up
		for(int j = y -1; j >= 0; j--){
			moves.add(new Point(x,j));
		}
		return moves;
	}
	
	/**
	 * check if move of Rook is legal
	 * @author Selman Selman and Jordan Beland
	 * @return true if the move is legal.
	 */
	public boolean checkIfLegal(int x, int y){
		if(x < 0 || x > Board.SIZE){
			return false;
		} else if(y < 0 || y > Board.SIZE){
			return false;
		} else{
			int xDiff = Math.abs(super.getX() - x);
			int yDiff = Math.abs(super.getY() - y);
			if (xDiff == 0 || yDiff == 0){
				return true;
			}
		}
		return false;
			
	}
}
